<template>
  <div id="collegemsg">
    <!-- 用户列表导航 -->
    <!-- 用户列表导航 -->
    <template>
      <div class="cic-breadcrumb">
        <el-breadcrumb separator-class="el-icon-arrow-right">
          <el-breadcrumb-item :to="{ path: '/' }">首页</el-breadcrumb-item>
          <el-breadcrumb-item>校园管理</el-breadcrumb-item>
          <el-breadcrumb-item>院别管理</el-breadcrumb-item>
        </el-breadcrumb>
      </div>
    </template>

    <!--视图 -->
    <el-card>
      <template>
        <div>
          <el-row>
            <el-col :span="20"></el-col>

            <el-col :span="2" :offset="19">
              <el-button type="primary" class="icon_position" @click="open">添加</el-button>
            </el-col>
          </el-row>
        </div>
      </template>
      <!-- 学院信息 start-->
      <template>
        <div class="cic-table">
          <el-table :data="tableData">
            <el-table-column type="index" label="序号" width="180"></el-table-column>

            <el-table-column prop="name" label="学院名称" width="180"></el-table-column>
          </el-table>
        </div>
      </template>
    </el-card>
  </div>
</template>
   
      
<script>
export default {
  inject: ["reload"],
  data() {
    return {
      college: {
        name: ""
      },
      collegeName: "",
      value: true,
      value1: true,
      // 表格数据
      tableData: []
      // 表格数据end
    };
  },
  created() {
    this.selectCollege();
  },
  methods: {
    // 查询所有学院
    selectCollege() {
      this.$get(this.$urlPath.school + "/school/colleges")
        .then(resp => {
          if (resp.code == 200) {
            if (resp.data == null) {
              this.tableData = null;
              this.$message({
                message: "暂无数据",
                type: "error"
              });
            } else {
              this.tableData = resp.data;
            }
          } else {
            return this.$message.error(resp.message);
          }
          console.log(resp);
        })
        .catch(error => {
          console.log(error);
        });
    },
    // 查询所有学院end
    open() {
      this.$prompt("请输入学院名", "提示", {
        confirmButtonText: "添加",
        cancelButtonText: "取消",
        beforeClose: (action, instance, done) => {
          let value = instance.inputValue;
          console.log(value);
          this.college.name = value;
          if (action == "cancel" || action == "close") {
            done();
          } else {
            if (value) {
              this.$post_json(
                // axios.post(
                this.$urlPath.school + "/school/college/add",
                this.college
              ).then(resp => {
                if (resp.code == 200) {
                  this.$message({
                    type: "success",
                    message: "你成功添加: " + this.value
                  });
                  done();
                  value: "";
                  instance.inputValue = "";
                  this.reload();
                } else {
                  return this.$message.error(resp.message);
                }
                console.log(resp);
              });
            } else {
              this.$message({
                type: "info",
                message: "输入内容不能为空！"
              });
            }
          }
        }
      })
        .then(({ value }) => {})
        .catch(error => {});
    }
  }
};
</script>


<style lang="less" >
@import "../../assets/less/golbal.less";
@import "../../assets/less/collegemsg.less";
</style>